<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>boosting查询 | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'query-dsl-boosting-query.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/query-dsl-boosting-query.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/query-dsl-boosting-query.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/query-dsl-boosting-query.html" rel="nofollow" target="_blank">../en/query-dsl-boosting-query.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch 权威指南 [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="query-dsl.html">查询领域特定语言(Query DSL)</a></span>
»
<span class="breadcrumb-link"><a href="compound-queries.html">复合查询</a></span>
»
<span class="breadcrumb-node">boosting查询</span>
</div>
<div class="navheader">
<span class="prev">
<a href="query-dsl-bool-query.html">« bool查询</a>
</span>
<span class="next">
<a href="query-dsl-constant-score-query.html">constant_score 查询 »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="query-dsl-boosting-query"></a>boosting查询
</h2>
</div></div></div>

<p>
返回匹配 <code class="literal">positive</code>(肯定) 查询的文档，同时降低匹配 <code class="literal">negative</code>(否定) 查询的文档的 <a class="xref" href="query-filter-context.html#relevance-scores" title="Relevance scores">相关性评分</a> 。
</p>
<p>
可以使用 <code class="literal">boosting</code> 查询来降级某些文档(降低其相关性评分)，但不会将它们从搜索结果中排除。
</p>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="boosting-query-ex-request"></a>请求示例
</h3>
</div></div></div>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET /_search
{
    "query": {
        "boosting" : {
            "positive" : {
                "term" : {
                    "text" : "apple"
                }
            },
            "negative" : {
                 "term" : {
                     "text" : "pie tart fruit crumble tree"
                }
            },
            "negative_boost" : 0.5
        }
    }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/97.console"></div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="boosting-top-level-params"></a>用于 <code class="literal">boosting</code> 的顶级参数
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">positive</code>
</span>
</dt>
<dd>
(必需的, query 对象) 你想运行的查询。 任何返回的文档都必须与该查询匹配。
</dd>
<dt>
<span class="term">
<code class="literal">negative</code>
</span>
</dt>
<dd>
<p>
(必需的, query 对象) 用于降低匹配文档的 <a class="xref" href="query-filter-context.html#relevance-scores" title="Relevance scores">相关性评分</a> 的查询。
</p>
<p>
如果返回的文档匹配 <code class="literal">positive</code> 查询和该查询，则 <code class="literal">boosting</code> 查询像下面这样计算该文档的最终 <a class="xref" href="query-filter-context.html#relevance-scores" title="Relevance scores">相关性评分</a> :
</p>
<div class="olist orderedlist">
<ol class="orderedlist">
<li class="listitem">
从 <code class="literal">positive</code> 查询中获取原始相关性评分。
</li>
<li class="listitem">
将该分数值乘以 <code class="literal">negative_boost</code> 值。
</li>
</ol>
</div>
</dd>
<dt>
<span class="term">
<code class="literal">negative_boost</code>
</span>
</dt>
<dd>
(必需的, float) 一个介于 <code class="literal">0</code> 和 <code class="literal">1.0</code> 之间的浮点数，用于降低与 <code class="literal">negative</code> 查询匹配的文档的 <a class="xref" href="query-filter-context.html#relevance-scores" title="Relevance scores">相关性评分</a>。
</dd>
</dl>
</div>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="query-dsl-bool-query.html">« bool查询</a>
</span>
<span class="next">
<a href="query-dsl-constant-score-query.html">constant_score 查询 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>